#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    : 2023/11/29 22:59
# @function: the script is used to do something.
# @version : 

from bs4 import BeautifulSoup
import requests
import os

from feapder.network.user_agent import get

path = '铃声/'
if not os.path.exists(path):
    os.mkdir(path)

for i in range(1, 10):
    url = 'https://sc.chinaz.com/yinxiao/index_{}.html'.format(i)
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'

    }
    response = requests.get(url, headers=headers).content.decode('utf-8')
    soup = BeautifulSoup(response, 'lxml')
    div_list = soup.select('#AudioList .container .audio-item')
    # print(div_list)
    for div in div_list:
        title = div.select('.name')[0].get_text().strip()
        mp3_url = "https:" + div.select('audio')[0].get('src')
        # print(title, mp3_url)
        # 再次发送请求
        res = requests.get(mp3_url, headers=headers)
        with open(path + title + '.mp3', 'wb') as f:
            f.write(res.content)
        print('下载{}完毕'.format(title))
